package com.wframe.project.jnd.util;

import com.wframe.project.jnd.entity.PurchaseGiftItem;

import java.math.BigDecimal;

/**
 * Created by lwb on 2017/6/7.
 */
public class PurchaseGiftPromotionHandler extends PromotionHandler {
    private PurchaseGiftItem item;

    public PurchaseGiftPromotionHandler(PurchaseGiftItem item) {
        this.item = item;
    }

    public PurchaseGiftItem handleRequest(BigDecimal price) {
        if (price.compareTo(this.item.getMinMoney()) >= 0) {
            this.item.setAvailable(true);
        } else {
            PurchaseGiftPromotionHandler successor = (PurchaseGiftPromotionHandler) getSuccessor();
            if (successor != null) {
                return successor.handleRequest(price);
            }
        }
        return this.item;
    }

    public PurchaseGiftItem handleRequest(int amount) {
        if (amount >= this.item.getMinNumber()) {
            this.item.setAvailable(true);
        } else {
            PurchaseGiftPromotionHandler successor = (PurchaseGiftPromotionHandler) getSuccessor();
            if (successor != null) {
                return successor.handleRequest(amount);
            }
        }
        return this.item;
    }
}
